const express = require("express")
const router = express.Router()
const multer = require("multer")

const storage = multer.diskStorage({
  destination: function (req, file, cb) {
    cb(null, "uploads")
  },
  filename: function (req, file, cb) {
    const uniqueSuffix = Date.now() + "-" + Math.round(Math.random() * 1e9)
    cb(null, uniqueSuffix + "-" + file.originalname)
  }
})

const upload = multer({ storage: storage })

router.post("/upload", upload.array("file", 5), function (req, res, next) {
  console.log(req.files);
  console.log(req.body);
  res.json({
    files:req.files,
    content: req.body
  })
})

module.exports = router